package com.tz.zczc.domain.model.common;

import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonInclude.Include;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import java.io.Serializable;
import java.util.Date;
import org.springframework.http.HttpStatus;

/**
 * @Author:Mark
 * @Description:
 * @Date: Created on 11:55 2018-12-6
 * @Modify by:
 */
@JsonInclude(Include.NON_NULL)
@ApiModel(
    value = "通用实体返回类",
    description = "用于所有接口的通用返回数据"
)
public class Response implements Serializable {

  @ApiModelProperty("返回消息的序列号")
  private String id;

  @ApiModelProperty("返回消息的请求的状态，具体代码的含义请参见 HttpStatus")
  private int code;

  @ApiModelProperty("返回的基本信息")
  private String msg;

  @ApiModelProperty("返回的数据信息")
  private Object data;

  @ApiModelProperty("返回数据的时间")
  @JsonFormat(
      pattern = "yyyy-MM-dd HH:mm:ss",
      timezone = "GMT+8"
  )
  private Date date;

  public static Response suc(Object data) {
    return new Response(HttpStatus.OK.value(), "请求成功", data);
  }

  public static Response badParam(String msg) {
    return new Response(HttpStatus.BAD_REQUEST.value(), msg);
  }

  public static Response notAllow(String msg) {
    return new Response(HttpStatus.FORBIDDEN.value(), msg);
  }

  public static Response error(String msg) {
    return new Response(HttpStatus.INTERNAL_SERVER_ERROR.value(), msg);
  }

  public String getId() {
    return this.id;
  }

  public Response setId(String id) {
    this.id = id;
    return this;
  }

  public String getMsg() {
    return this.msg;
  }

  public Response setMsg(String msg) {
    this.msg = msg;
    return this;
  }

  public Object getData() {
    return this.data;
  }

  public Response setData(Object data) {
    this.data = data;
    return this;
  }

  public Date getDate() {
    return this.date;
  }

  public int getCode() {
    return this.code;
  }

  public Response setCode(int code) {
    this.code = code;
    return this;
  }

  public Response setDate(Date date) {
    this.date = date;
    return this;
  }

  public Response(int code, String msg) {
    this.id = System.currentTimeMillis() + "";
    this.msg = msg;
    this.code = code;
    this.date = new Date();
  }

  public Response(int code, String msg, Object data) {
    this.id = System.currentTimeMillis() + "";
    this.code = code;
    this.msg = msg;
    this.data = data;
    this.date = new Date();
  }

  public Response(String id,  int code, String msg, Object data, Date date) {
    this.id = id;
    this.code = code;
    this.msg = msg;
    this.data = data;
    this.date = date;
  }

  public Response() {
  }

  @Override
  public String toString() {
    return "Response{" +
        "id='" + id + '\'' +
        ", code=" + code +
        ", msg='" + msg + '\'' +
        ", data=" + data +
        ", date=" + date +
        '}';
  }
}
